layui.define(['table', 'form','laypage','laydate','layer'], function(exports){
    var $ = layui.$
        ,table = layui.table
        ,form = layui.form
        , laydate=layui.laydate
        , laypage = layui.laypage
        , layer = layui.layer;

    //路径
    var curWwwPath=window.document.location.href;
    var pathName=window.document.location.pathname;
    var pos=curWwwPath.indexOf(pathName);
    var localhostPaht=curWwwPath.substring(0,pos);
    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);

    var limitcount = 10;
    table.render({
        elem: '#inspection'
        , url: localhostPaht + projectName + "/rest/inspection/inspectionBackstageList"
        ,title:"场地巡检单",
        height: 'full-193'
        , page: false
        , limit: limitcount
        , text: {
            none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
        },
        defaultToolbar: ['filter','print']
        , cols: [[
            {field: 'number', title: 'ID', width: 70, sort: true,fixed:'left'}
            , {field: 'inspectionEpc', title: 'EPC标签', sort: true}
            , {field: 'inspectionName', title: '巡检地点', sort: true}
            , {field: 'inspectionPerson', title: '巡检人员', sort: true}
            , {field: 'createTime', title: '操作时间', sort: true}
            , {title: '操作', toolbar: '#table-inspection', align: "center", width: 200}

        ]],
        done: function (res, curr, count) {
            if(res.errorMsg==null){

            }else {
                layer.msg(res.errorMsg);
            }
            var curnum = $("#curnum").val();
            laypage.render({
                elem: 'laypage'
                ,first: '首页'
                ,last: '尾页'
                ,groups:5
                , count: count
                , curr: curnum
                , limit: limitcount
                , layout: ['prev', 'page', 'next', 'skip', 'count','limit']
                , limits:[10,15,20]
                , jump: function (obj, first) {
                    if (!first) {
                        curnum = obj.curr;
                        $("#curnum").val(curnum)
                        limitcount = obj.limit;
                        table.reload('inspection', { //表格的id
                            where: {
                                page: curnum,
                                limit:limitcount
                            }
                        })
                    }
                }
            })
        }
    });

    //监听工具条
    table.on('tool(inspections)', function(obj){  //表格的lay-filter="userlists"
        var data = obj.data; //获得当前行所有数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        var tr = obj.tr; //获得当前行 tr 的DOM对象
        if(obj.event=='info'){
            info(data);
        }
    });
    function info(data){
        layer.open({
            title : "详情",
            type: 2,
            content: localhostPaht + projectName +  '/rest/getRoute?type=rfid&url=inspection_info',
            maxmin: true,
            area: ['90%', '91%'],
            shade:0.6,
            anim: 4,
            skin: 'layui-layer-molv',
            resize:true,
            success: function(layero, index){  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                // var body = layer.getChildFrame('body',index);//建立父子联系  //当你试图在当前页获取iframe页的DOM元素时，你可以用此方法。
                // body.find("#id").val(data.id);
                var iframe = window['layui-layer-iframe'+index];
                //调用子页面的全局函数
                iframe.child(data.id)
            }
        });
    }
    exports('inspection', {})
});